import java.util.Arrays;
import java.util.Scanner;

public class Main10 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        PersonSortable[] personSortables = new PersonSortable[n];
        for (int i = 0; i < n; i++) {
            String string = scanner.nextLine();
            String[] strings = string.split(" ");
            personSortables[i] = new PersonSortable(strings[0], Integer.parseInt(strings[1]));
        }
        Arrays.sort(personSortables);
        for (PersonSortable p:
             personSortables) {
            System.out.println(p);
        }
        System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
    }
}

class PersonSortable implements Comparable<PersonSortable>{

    private String name;
    private int age;

    public PersonSortable(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return  name + "-" + age;
    }

    @Override
    public int compareTo(PersonSortable o) {
        if (o.name.compareTo(this.name) > 0) {
            return -1;
        } else if (o.name.compareTo(this.name) < 0) {
            return 1;
        } else {
            return this.age - o.age;
        }
    }
}
